package com.baidu.health.controller;

import com.baidu.health.pojo.TbGoods;
import com.baidu.health.pojo.TbStore;
import com.baidu.health.service.TbStoreService;
import com.baidu.health.util.ResultR;
import com.baidu.health.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: 孙新超
 *
 * @author 孙新超
 * @version 1.0
 * @date To change this template use File | Settings | File Templates.
 * @date
 */
@Api(tags = "商城")
@RestController
@RequestMapping("/store")
public class TbStoreController {
    @Autowired
    private TbStoreService service;

    //商家信息
    @ApiOperation("商家信息")
    @PostMapping("storelist")
    public ResultResponse storelist(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "3") Integer size) {
        return service.storelist(page, size);
    }

    //商家新增商品
    @ApiOperation("商家新增商品")
    @PostMapping("storeadd")
    public ResultResponse storeadd(@RequestBody TbStore tbStore) {
        return service.storeadd(tbStore);
    }

    //商家删除商品
    @ApiOperation("商家删除商品")
    @PostMapping("storedel")
    public ResultResponse storedel(@RequestParam("storeId") String storeId) {
        return service.storedel(storeId);
    }

    //商家修改商品信息
    @ApiOperation("商家修改商品信息")
    @PostMapping("storeupdate")
    public ResultResponse storeupdate(@RequestBody TbStore tbStore) {
        return service.storeupdate(tbStore);
    }

    //通过登录判断是否为商家
    @ApiOperation("通过登录判断是否为商家")
    @PostMapping("rolelist")
    public ResultResponse rolelist(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "3") Integer size,
                                    Integer userId, Byte userRole) {

        return service.rolelist(page, size, userId, userRole);
    }

    //商家查看商品信息
    @ApiOperation("商家查看商品信息")
    @PostMapping("storegoodslist")
    public ResultResponse storegoodslist(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "3") Integer size,
                                         Integer storeId) {
        return service.storegoodslist(page, size, storeId);
    }

    //指定商家添加商品
    @ApiOperation("指定商家添加商品")
    @PostMapping("storegoodsadd")
    public ResultResponse storegoodsadd(@RequestBody TbGoods tbGoods,
                                        Integer storeId) {
        return service.storegoodsadd(tbGoods, storeId);
    }
    //审核商品列表
    @ApiOperation("审核商品列表")
    @PostMapping("ckhecjlist")
    public ResultResponse ckhecjlist(@RequestParam Map<String,Object> params){
        return  service.ckhecjlist(params);
    }
    //审核商品
    @ApiOperation("审核商品")
    @PostMapping("auditgoods/{goodsId}/{goodsState}")
    public ResultResponse auditgoods(@PathVariable Integer goodsId,
                                     @PathVariable Integer goodsState
                                     ){
        return service.auditgoods(goodsId,goodsState);
    }
    //管理员审核商品

    @ApiOperation("管理员审核商品")
    @PostMapping("adminlist")
    public ResultResponse adminlist(@RequestParam(defaultValue = "1")Integer page,
                                      @RequestParam(defaultValue = "3")Integer size,
                                      Integer userId,Byte userRole,Integer storeId

                                      ){
        return service.adminlist(page,size,userId,userRole,storeId);
    }
    //商品审核
    @ApiOperation("商品审核")
    @PostMapping("updategoods")
    public ResultResponse updategoods(@RequestBody TbGoods tbGoods,
                                      Integer goodsId
    ){
        return service.updategoods(goodsId,tbGoods);
    }
}
